#include "stdafx.h"
#include "Video.h"
#include "clientinterfaces.h"

std::string Video_date::m_file_root="rez\\movies\\";
Video_date::Video_date( const std::string& _video_name ):
uses(1),
m_file_name(m_file_root+_video_name)
{
	//LTRESULT hr;
	//hr=g_pLTVideoManager->StartOnScreenVideo("rez\\movies\\open.wmv",PLAYBACK_FULLSCREEN, m_video);
}

Video_date::~Video_date()
{
	if (m_video)
	{
		LTRESULT hr=g_pLTVideoManager->StopVideo(m_video);
		if (hr!=LT_OK)
		{
			if (hr==LT_NOTINITIALIZED)
			{
				throw(Video_error("~Video_date : vedio not initalized"));
			}
			else if (hr==LT_INVALIDPARAMS)
			{
				throw(Video_error("~Video_date : vedio is invalid"));
			}
		}
	}

}

Video::Video():
m_date(0)
{


}

Video::Video(const std::string& _name )
{
	m_date=new Video_date(_name);
}

Video::Video( const Video& _video )
{
	if (this==&_video||_video.m_date==0)
	{
		return;
	}
	m_date=_video.m_date;
	if (m_date)
	{
		++m_date->uses;
	}
	
	
}


Video::~Video()
{
	if (m_date)
	{
		--m_date->uses;
		if (m_date->uses==0)
		{
			try
			{
				delete m_date;
			}
			catch(Video_error _error)
			{

			}
			m_date=0;
		}
		
	}
	


}

Video& Video::operator=( const Video& _video )
{
	if (this==&_video||_video.m_date==0)
	{
		return *this;
	}
	if (m_date)
	{
		--m_date->uses;
		if (m_date->uses==0)
		{
			try
			{
				delete m_date;
			}
			catch(Video_error _error)
			{

			}
			m_date=0;
		}
	}
	m_date=_video.m_date;
	m_date->uses++;
	return *this;
}